package org.catlabs.patterns.observer.observer;

import org.catlabs.patterns.observer.subject.Subject;

public class CurrentConditionsDisplay implements Display, Observer {

    private Subject weatherData;
    float temperature, humidity; // Only these are relevant to this display
    
    /**
     * It not only holds a reference to the Subject but it also
     * subscribes itself to the Subject (makes sense, people subscribe 
     * to magazines, magazines doesn't pick people)
     * 
     * @param weatherData
     */
    public CurrentConditionsDisplay(Subject weatherData){
	this.weatherData = weatherData;
	this.weatherData.registerObserver(this);
    }
    
    @Override
    public void display() {
	System.out.println("Current conditions");
	System.out.println("Temperature: "+temperature+" Celcius");
	System.out.println("Humidity: "+humidity+"%\n");
    }

    @Override
    public void update(float temp, float humidity, float pressure) {
	this.temperature = temp;
	this.humidity = humidity;
	display();
    }


}
